from datetime import datetime, timedelta

from interface import Button, TaskAtom, TaskBase, RegularTask

class SignInTaskAtom(TaskAtom):
    def __init__(self):
        super().__init__('培育室', 'SignInTask', ['每日补给', '领取', '继续', '返回'])
    
    def run(self, button_dict:dict[str, Button]):
        for button_name in self.button_name_list:
            if button_name not in button_dict.keys():
                raise ValueError(f"Button {button_name} not found in button_dict")
            button_dict[button_name].tap(wait=True)
        

class SignInTask(RegularTask):
    def __init__(self):
        super().__init__('SignInTask', task_list=[
            SignInTaskAtom()
        ])
        self.activate_time = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
    
    def is_complete(self):
        return False
    
    def run(self, button_dict:dict[str, Button]):
        self.taskatom_list[self.next].run(button_dict)
        self.current_priority = 0
        self.activate_time += timedelta(days=1)
        self.next = (self.next + 1) % len(self.taskatom_list)
        print(f'{self.task_name} finished')